#!/usr/bin/python
# -*- coding: utf-8 -*-

#This file is part of pyLot library.
#
# pyLot is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# pyLot is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with pyLot.  If not, see <http://www.gnu.org/licenses/>.

__author__ = u'Pierre Puiseux, Guillaume Baty'
__copyright__ = u"Copyright 2011-2012 (C) andheo, Université de Pau et des Pays de l'Adour"
__credits__ = [u'Pierre Puiseux', u'Guillaume Baty']
__license__ = "GNU Lesser General Public License"

__all__ = [u'GuiStatusBar']

import sys

from pyLot.core import (check_type, check_keys)
from pyLot.interfaces import WriterInterface

from _pylot.qtgui.styles.charformats import PYLOT_CHAR_FORMATS
from _pylot.qtgui.interfaces.widgetinterface import WidgetInterface

from Qt4 import QtGui

class GuiStatusBar(QtGui.QStatusBar, WidgetInterface, WriterInterface):

  def __init__(self, formats=PYLOT_CHAR_FORMATS):
    u"""
    :param formats: a dict of QTextCharFormat
    :type formats: obj:`dict`
    """
    QtGui.QStatusBar.__init__(self)
    WidgetInterface.__init__(self)
    WriterInterface.__init__(self) #it seems but it's not a duplicated line ! 

    # TODO: property
    check_type(u'formats', formats, dict)
    for name, fmt in formats.items() :
      check_type(name, fmt, QtGui.QTextCharFormat)
    check_keys(u'formats', formats, [u'std'])
    self.formats = formats
    pass

  def _write (self, text, style):
    self.showMessage(text)

  def _clear(self):
    self.clearMessage()

if __name__ == u"__main__":
  app = QtGui.QApplication(sys.argv)
  win = QtGui.QMainWindow()

  widget = GuiTextView()
  win.setCentralWidget(widget)
  for tool_bar in widget.tool_bars :
    win.addToolBar(tool_bar)
  for menu in widget.menus :
    win.menu_bar.addMenu(menu)

  if widget.pref :
    widget.pref.show()

  widget.write(u'salut\n', u'title')
  widget.write(u'¡ ça marche ! συγχαρητήρια ! 祝賀 !', u'warn')

  win.show()

  app.exec_()

  import doctest
  doctest.testmod()
